package com.common;

import java.net.URISyntaxException;

public class CommonUtil {
	public static String getRootPath() {
		String result = null;
		try {
			result = CommonUtil.class.getResource("CommonUtil.class").toURI()
					.getPath().toString();
		} catch (URISyntaxException e1) {
			e1.printStackTrace();
		}
		int index = result.indexOf("WEB-INF");
		if (index == -1) {
			index = result.indexOf("bin");
		}
		if(WindowOrLinux()){
			result = result.substring(1, index);
		}else{
			result = result.substring(0, index);
		}
		if (result.endsWith("/"))
			result = result.substring(0, result.length() - 1);// 不包含最后的"/"
		return result;
	}
	
	public static boolean WindowOrLinux() {
		if (System.getProperty("os.name").toUpperCase().indexOf("WINDOWS") != -1) {
			return true;
		}
		return false;
	}
	public static boolean isNullObject(Object object) {
		if (object == null || "".equals(object.toString())
				|| "null".equals(object.toString())) {
			return true;
		}
		return false;
	}
}
